package base;

import java.awt.Graphics;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import parser.CParser;

/*
 * CFrame.java
 *
 * Created on 01.12.2010, 15:39:05
 */

public class CFrame extends javax.swing.JFrame {
    /** Creates new form CFrame */
    public CFrame() {
        initComponents();
		//setExtendedState( getExtendedState()|JFrame.MAXIMIZED_BOTH);
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    Canvas = new JPanel() {
      public void paintComponent( Graphics G ) {
        CGraphics.Draw( G );
      }	
    };

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setMinimumSize(new java.awt.Dimension(248, 354));
    addComponentListener(new java.awt.event.ComponentAdapter() {
      public void componentResized(java.awt.event.ComponentEvent evt) {
        formComponentResized(evt);
      }
    });
    addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        formKeyPressed(evt);
      }
    });

    Canvas.setMinimumSize(new java.awt.Dimension(240, 320));
    Canvas.setPreferredSize(new java.awt.Dimension(248, 400));
    Canvas.setRequestFocusEnabled(false);
    Canvas.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mousePressed(java.awt.event.MouseEvent evt) {
        CanvasMousePressed(evt);
      }
      public void mouseReleased(java.awt.event.MouseEvent evt) {
        CanvasMouseReleased(evt);
      }
    });
    Canvas.addComponentListener(new java.awt.event.ComponentAdapter() {
      public void componentResized(java.awt.event.ComponentEvent evt) {
        CanvasComponentResized(evt);
      }
    });
    Canvas.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
      public void mouseDragged(java.awt.event.MouseEvent evt) {
        CanvasMouseDragged(evt);
      }
      public void mouseMoved(java.awt.event.MouseEvent evt) {
        CanvasMouseMoved(evt);
      }
    });

    javax.swing.GroupLayout CanvasLayout = new javax.swing.GroupLayout(Canvas);
    Canvas.setLayout(CanvasLayout);
    CanvasLayout.setHorizontalGroup(
      CanvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 640, Short.MAX_VALUE)
    );
    CanvasLayout.setVerticalGroup(
      CanvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 480, Short.MAX_VALUE)
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(Canvas, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(Canvas, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents









	private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
		if ( evt.getKeyCode() == KeyEvent.VK_ESCAPE ) CProject.Action = CProject.MainMenu;
		if ( evt.getKeyCode() == KeyEvent.VK_F11 ) CParser.LogCases();
	}//GEN-LAST:event_formKeyPressed

	private void CanvasMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CanvasMouseMoved
		CGraphics.MouseX = evt.getX();
		CGraphics.MouseY = evt.getY();
		Canvas.repaint();
	}//GEN-LAST:event_CanvasMouseMoved

	private void CanvasComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_CanvasComponentResized
		if( CGraphics.Component != null ) CProject.UpdateDesign = true;
	}//GEN-LAST:event_CanvasComponentResized

	private void CanvasMouseDragged( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_CanvasMouseDragged
		CWindow Window = CGUI.DraggingSliderWindow;
		if( Window != null ) {
			Window.YShift = CGUI.StartingYShift + (int) 1.0 * ( evt.getY() - CGUI.StartingY ) * Window.Height / Window.ViewHeight;
			Canvas.repaint();
		}
	}//GEN-LAST:event_CanvasMouseDragged

	private void CanvasMousePressed( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_CanvasMousePressed
		if ( CGUI.GadgetUnderMouse != null ) {
			CProject.SelectedGadget = CGUI.GadgetUnderMouse;
			CProject.Action = CProject.MenuAction;
		}
		CGUI.InformationWindow.CheckScrollBarButtonPress( evt );
		CGUI.DescriptionWindow.CheckScrollBarButtonPress( evt );
	}//GEN-LAST:event_CanvasMousePressed

	private void CanvasMouseReleased( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_CanvasMouseReleased
		CGUI.DraggingSliderWindow = null;
	}//GEN-LAST:event_CanvasMouseReleased

  private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
    
  }//GEN-LAST:event_formComponentResized


  // Variables declaration - do not modify//GEN-BEGIN:variables
  public javax.swing.JPanel Canvas;
  // End of variables declaration//GEN-END:variables
}
